var ${table.entityPath}_page={};
// 动作
${table.entityPath}_page.action = {
    initBody:function () {
        ${table.entityPath}_page.interface.initTablePage();
        ${table.entityPath}_page.action.bindEvent();
    },
    bindEvent:function () {
        $("#addBtn").click(function () {
            ${table.entityPath}_page.interface.openFormPage();
            return false;
        });
        $("#cancelBtn").click(function () {
            ${table.entityPath}_page.action.initBody();
            return false;
        });
        $("#deleteBtn").click(function () {
            ${table.entityPath}_page.action.deleteBtnClick();
        });
    },
    deleteBtnClick:function (id) {
        if(id==null||id==""){
            AppComm.layer.warm(checkResult.msg);
        } else {
            AppComm.ajax.post('/${table.entityPath}/ajax/delete', {
                id:id
            }, function(){
                ${table.entityPath}_page.data.tableIns.reload();
            });
        }
    }
};
// 界面
${table.entityPath}_page.interface = {

    // 加载表格页
    initTablePage:function () {
<#--        var html = template("${table.entityPath}List_template");-->
<#--        $(".${table.entityPath}_box").html(html);-->
        layui.use(['table','form'], function(){
            var table = layui.table;
            //执行表格渲染
            var tableIns = table.render({
                height:625,
                url:${table.entityPath}_page.data.preAjax+'/getList',
                elem:"#tb_list",
                page: true,
                limit:14,
                loading:true,
                id:'id',
                cols: [[
    <#list cfg.tableFieldList as tableField>
                    {
                        field:'${tableField.propertyName}',
                        title:'${tableField.comment}',
                        align:'left',
                        width:200
                    },
    </#list>
                    {
                        title:'操作',
                        fixed:'right',
                        width:180,
                        align:'center',
                        toolbar:'#toolbar'
                    }
                ]]
            });

            ${table.entityPath}_page.data.tableIns = tableIns;

            table.on('tool(tb_list)', function (obj) {
                var rowData = obj.data;
                var layEvent = obj.event;
                if (layEvent==='editBtn') {
                    ${table.entityPath}_page.interface.openFormPage(rowData.id);
                }
                if (layEvent==='deleteBtn') {
                    AppComm.layer.confirm('确定要进行删除吗？', function () {
                        ${table.entityPath}_page.action.deleteBtnClick(rowData.id);
                    });
                }
            });
            // 查询
            var form = layui.form;
            form.render(null, 'searchForm');
                form.on('submit(searchBtn)', function (data) {
                    var postData = {
    <#list cfg.tableFieldList as tableField>
                        ${tableField.propertyName}: data.field.${tableField.propertyName},
    </#list>
                    };
                    tableIns.reload({
                        page: {curr:1},
                        where: postData
                    });
                    return false;
                });
            }
        );
    },
    openFormPage:function(rowId){
        AppComm.layer.open(${table.entityPath}_page.data.preForm+'/testForm', null,function (layero, index) {
            var iframeWin = AppComm.utils.iframeWin(layero);
            if (rowId != undefined && '' != rowId.trim()) {
                iframeWin.${table.entityPath}Form_page.data.rowId = rowId;
            }
            iframeWin.${table.entityPath}Form_page.action.initBody();
        });
    }

};
// 数据
${table.entityPath}_page.data = {
    'tableIns':undefined,
    'preAjax':'/${table.entityPath}/ajax',
    'preForm':'/${table.entityPath}/form',
    'action':""
};

AppComm.initFrame(${table.entityPath}_page);